﻿<Window x:Class="WPF.Samples1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:WPF.Samples1"
        Title="MainWindow" Height="350" Width="525">


    <Canvas>
        <Canvas.Resources>
            <ControlTemplate x:Key="MoveThumbTemplate" TargetType="{x:Type s:MoveThumb}">
                <Rectangle Fill="Transparent" />
            </ControlTemplate>
            <ControlTemplate x:Key="ResizeDecoratorTemplate" TargetType="{x:Type Control}" >
                <Grid>
                    <s:ResizeThumb Height="3" Cursor="SizeNS" Margin="0 -4 0 0"
                       VerticalAlignment="Top" HorizontalAlignment="Stretch"/>
                    <s:ResizeThumb Width="3" Cursor="SizeWE" Margin="-4 0 0 0"
                       VerticalAlignment="Stretch" HorizontalAlignment="Left"/>
                    <s:ResizeThumb Width="3" Cursor="SizeWE" Margin="0 0 -4 0"
                       VerticalAlignment="Stretch" HorizontalAlignment="Right"/>
                    <s:ResizeThumb Height="3" Cursor="SizeNS" Margin="0 0 0 -4"
                       VerticalAlignment="Bottom" HorizontalAlignment="Stretch"/>
                    <s:ResizeThumb Width="7" Height="7" Cursor="SizeNWSE" Margin="-6 -6 0 0"
                       VerticalAlignment="Top" HorizontalAlignment="Left"/>
                    <s:ResizeThumb Width="7" Height="7" Cursor="SizeNESW" Margin="0 -6 -6 0"
                       VerticalAlignment="Top" HorizontalAlignment="Right"/>
                    <s:ResizeThumb Width="7" Height="7" Cursor="SizeNESW" Margin="-6 0 0 -6"
                       VerticalAlignment="Bottom" HorizontalAlignment="Left"/>
                    <s:ResizeThumb Width="7" Height="7" Cursor="SizeNWSE" Margin="0 0 -6 -6"
                       VerticalAlignment="Bottom" HorizontalAlignment="Right"/>
                </Grid>
            </ControlTemplate>

            <ControlTemplate x:Key="DesignerItemTemplate" TargetType="ContentControl">
                <Grid  DataContext="{Binding RelativeSource={RelativeSource TemplatedParent}}">
                    <s:MoveThumb Template="{StaticResource MoveThumbTemplate}"  DataContext="{Binding RelativeSource={RelativeSource TemplatedParent}}"
                Cursor="SizeAll" />
                    <Control Template="{StaticResource ResizeDecoratorTemplate}" />
                    <ContentPresenter Content="{TemplateBinding ContentControl.Content}" />
                </Grid>
            </ControlTemplate>
        </Canvas.Resources>
        <ContentControl Name="DesignerItem" Width="100" Height="100" Canvas.Top="100"
            Canvas.Left="100" Template="{StaticResource DesignerItemTemplate}">
            <Ellipse Fill="Blue" IsHitTestVisible="False" />
        </ContentControl>

    </Canvas>
</Window>
